package org.example.corpus.bilingual.service.impl;

import org.example.corpus.bilingual.controller.dto.translation.TranslationRequest;
import org.example.corpus.bilingual.controller.dto.translation.TranslationResponse;
import org.example.corpus.bilingual.dao.bilingualDao;
import org.example.corpus.bilingual.service.bilingualService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class bilingualServiceImpl implements bilingualService {
    @Autowired
    private bilingualDao bilingualDao;

    @Override
    public TranslationResponse importData(TranslationRequest request) {
        List<String> sourceSentences = request.getSourceSentences();
        List<String> targetSentences = request.getTargetSentences();
        boolean isAligned = request.isAligned();

        if (sourceSentences == null || targetSentences == null || sourceSentences.size() != targetSentences.size()) {
            TranslationResponse response = new TranslationResponse();
            response.setCode(1);
            response.setMessage("请求参数错误");
            return response;
        }

        int insertedCount = 0;
        int duplicateCount = 0;

        for (int i = 0; i < sourceSentences.size(); i++) {
            String source = sourceSentences.get(i);
            String target = targetSentences.get(i);

//            if (bilingualDao.exists(source, target)) {
//                duplicateCount++;
//            } else {
//                bilingualDao.insert(source, target, isAligned);
//                insertedCount++;
//            }
        }

        TranslationResponse response = new TranslationResponse();
        TranslationResponse.Data data = new TranslationResponse.Data();
        data.setInsertedCount(insertedCount);
        data.setDuplicateCount(duplicateCount);
        response.setCode(0);
        response.setMessage("导入成功");
        response.setData(data);

        return response;
    }
}
